package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	filecopy("target.txt", "source.txt")
	fmt.Println("文件复制完成")
}

func filecopy(dst, src string) (int64, error) {
	dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		return 0, err
	}
	defer dstFile.Close()
	srcFile, err := os.Open(src)
	if err != nil {
		return 0, err
	}
	defer srcFile.Close()
	return io.Copy(dstFile, srcFile)
}
